import {
  myRequesy
} from '../../request/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 选项卡 
    tablist: [{
        name: "收到的赞",
        status: true,
        id: 0
      },
      {
        name: "我赞过的",
        status: false,
        id: 1
      }
    ],
    setoutlist: [], // 收到的赞列表
    mypraiselist: [], // 我赞过的列表
    RrpageNum: 1, //收到的赞页码值
    MypageNum: 1, //我赞过的页码值
    RenextPage: null,
    MynextNum: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getPraiseList()

    
  },
  // 顶部评论/切换的回调
  btnTab(e) {
    let index = e.currentTarget.dataset.index
    let tablist = this.data.tablist
    tablist.map((item, i) => i === index ? item.status = true : item.status = false)
    this.setData({
      tablist,
      RrpageNum: 1,
      MypageNum: 1
    })

    if (index === 1) {
      this.getMyList()
    } else {
      this.getPraiseList()
    }
  },



  // 收到的赞列表
  getPraiseList() {
    let that = this
    myRequesy({
      url: 'user/received-likes',
      data: {
        page: that.data.RrpageNum
      }
    }).then(res => {
      if (res.data.code === 0) {
        that.setData({
          setoutlist: res.data.data,
          RenextPage: res.data.next_url
        })
      }
      console.log(res);

    })
  },

  // 我赞过的列表
  getMyList() {
    let that = this
    myRequesy({
      url: 'user/send-likes',
      data: {
        page: that.data.MypageNum
      }
    }).then(res => {
      if (res.data.code === 0) {
        that.setData({
          mypraiselist: res.data.data,
          MynextNum: res.data.next_url
        })
      }
      console.log(res);

    })
  },


  // 上拉获取更多收到的赞
  getBomPraise() {
    let that = this
    if (that.data.RenextPage !== null) {
      let that = this
      that.data.RrpageNum += 1
      myRequesy({
        url: 'user/received-likes',
        data: {
          page: this.data.RrpageNum
        }
      }).then(res => {
        if (res.data.code === 0) {
          that.setData({
            setoutlist: [...that.data.setoutlist, ...res.data.data],
            RenextPage: res.data.next_url
          })
        }
      })
      return
    }
  },

  // 上拉获取更多我的赞
  getBomMy() {
    let that = this
    if (that.data.MynextNum !== null) {
      that.data.MypageNum += 1
      myRequesy({
        url: 'user/send-likes',
        data: {
          page: this.data.MypageNum
        }
      }).then(res => {
        if (res.data.code === 0) {
          that.setData({
            mypraiselist: [...that.data.mypraiselist, ...res.data.data],
            MynextNum: res.data.next_url
          })
        }
      })
      return
    }
  },



  //点击头像跳转到用户动态
  headleNav(e) {
    wx.navigateTo({
      url: '/pages/dynamic/dynamic?id=' + e.currentTarget.dataset.id,
    })
  },

  // 点击评论图片跳转到
  headleDeta(e) {
    console.log(e);
    wx.navigateTo({
      url: '/pages/details/details?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  onHide: function () {

  },



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getBomMy()
    this.getBomPraise()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})